{% extends 'search_result.html' %}
{% block page_title %}#{{ question.id }} {{ question.title }}{% endblock page_title %}
{% block navbar_status %}
<li class="active"><a href="#">详情 <span class="sr-only">(current)</span></a></li>
<li><a type="submit" href="/community/question/?q=11" target="_blank">Github</a></li>
{% endblock navbar_status %}
{% block nav_other %}

{% endblock nav_other %}
{% block main_div %}
<div class="col-md-12">
    <div class="page-header">
    <h1>#{{ question.id }} {{ question.title }} <br><small>{{ question.tags }}</small></h1>
</div>
<div class="col-md-10">
<ol class="breadcrumb">
  <li><a href="/community/group">Community</a></li>
  {% if request.GET.gname != None %}
  <li><a class="text-capitalize" href="/community/group/?gname={{ request.GET.gname }}">{{ request.GET.gname }}</a></li>
  {% else %}
  <li><a class="text-capitalize" href="/community/group/?gname=world">world</a></li>
  {% endif %}
  <li class="active">#{{ question.id }}</li>
</ol>
</div>
<div class="col-md-10" >
    <div class="panel 
    {% if question.status == 0 or question.status == None %}
    panel-default
    {% elif question.status == 1 %}
    panel-success
    {% elif question.status == 2 %}
    panel-info
    {% elif question.status == 3 %}
    panel-warning
    {% elif question.status == 4 %}
    panel-danger
    {% endif %}">
        <div class="panel-heading"><b>{{ question.user.name }}</b>的提问: 
        {% if user.uid == question.user.uid %}
        <!-- Split button -->
        <div class="btn-group navbar-right" style="margin-right: 5px;">
        <a type="button" class=" dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="color:black;">
            <span class="glyphicon glyphicon-cog"></span>
            <span class="sr-only">Toggle Dropdown</span>
        </a>
        <ul class="dropdown-menu">
            <li><a href="/community/editquestion/?id={{ question.id }}&gname={{ request.GET.gname }}">重新编辑 <span class="glyphicon glyphicon-edit"></span></a></li>
            {% if question.canlink == 1 %}
            <li><a href="/community/editquestion/?id={{ question.id }}&gname={{ request.GET.gname }}&canlink=0">Close Link <span class="glyphicon glyphicon-remove"></span></a></li>
            {% else %}
            <li><a href="/community/editquestion/?id={{ question.id }}&gname={{ request.GET.gname }}&canlink=1">Open Link <span class="glyphicon glyphicon-ok"></span></a></li>
            {% endif %}
            <li role="separator" class="divider"></li>
            {% if question.status != 1 %}
            <li><a href="/community/editquestion/?id={{ question.id }}&gname={{ request.GET.gname }}&status=1">Solved </a></li>
            {% endif %}
            {% if question.status != 4 %}
            <li><a href="/community/editquestion/?id={{ question.id }}&gname={{ request.GET.gname }}&status=4">Close </a></li>
            {% endif %}
            {% if question.status > 0 %}
            <li><a href="/community/editquestion/?id={{ question.id }}&gname={{ request.GET.gname }}&status=0">恢复默认状态 </a></li>
            {% endif %}
            <li role="separator" class="divider"></li>
            <li><a href="/community/question_delete?q={{ request.GET.q }}&id={{ question.id }}&t=q&gname={{ request.GET.gname }}">删除提问 <span class="glyphicon glyphicon-trash"></span></a></li>
        </ul>
        </div>
        {% comment %} <div class="navbar-right"><a href="/community/question_delete?q={{ request.GET.q }}&id={{ question.id }}&t=q" style="color: black; margin-right: 20px;">删除提问 <span class="glyphicon glyphicon-trash"></span></a></div>
        <div class="navbar-right"><a href="/community/editquestion/?id={{ question.id }}&gname={{ request.GET.gname }}" style="color: black; margin-right: 20px;">重新编辑 <span class="glyphicon glyphicon-edit"></span></a></div> {% endcomment %}
        {% else %}
        <!-- Split button -->
        <div class="btn-group navbar-right" style="margin-right: 5px;">
        <a type="button" class=" dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" style="color:black;">
            <span class="glyphicon glyphicon-triangle-bottom"></span>
            <span class="sr-only">Toggle Dropdown</span>
        </a>
        <ul class="dropdown-menu">
            {% if ";"|add:user.name|add:"'s_Favorites;" in question.group %}
            <li><a href="/community/question_group_remove/?id={{ question.id }}&gname={{ request.GET.gname }}&tgname={{ user.name }}'s_Favorites">Remove from Favorites <span class="glyphicon glyphicon-star"></span></a></li>
            {% else %}
            <li><a href="/community/question_group_add/?id={{ question.id }}&gname={{ request.GET.gname }}&tgname={{ user.name }}'s_Favorites">Add to Favorites <span class="glyphicon glyphicon-star-empty"></span></a></li>
            {% endif %}
        </ul>
        </div>
        {% endif %}
        </div>
        <div id="{{ question.id }}" class="panel-body">
                <!-- Server-side output Markdown text -->
            <textarea style="display:none;">{{ question.content }}</textarea>             
        </div>
        <div class="panel-footer text-right">{{ question.time }}</div>
        </div>
    <script type="text/javascript">
    $(function() {
        var testView = editormd.markdownToHTML("{{ question.id }}", {
            // markdown : "[TOC]\n### Hello world!\n## Heading 2", // Also, you can dynamic set Markdown text
            // htmlDecode : true,  // Enable / disable HTML tag encode.
            // htmlDecode : "style,script,iframe",  // Note: If enabled, you should filter some dangerous HTML tags for website security.
        });
    });
    </script>  
</div>
{% for com in coms %}
<div class="col-md-10" >
    <div class="panel panel-primary">
        <div id="F{{ com.id }}" class="panel-heading"><b>{{ com.user.name }}</b>的回答: 
        {% if user.uid == com.user.uid and question.status != 4 %}
        <div class="navbar-right"><a href="/community/question_delete?q={{ request.GET.q }}&id={{ com.id }}&t=c&gname={{ request.GET.gname }}" style="color: white; margin-right: 20px;">删除回答 <span class="glyphicon glyphicon-trash"></span></a></div>
        <div class="navbar-right"><a href="/community/editquestioncomment/?qid={{ question.id }}&gname={{ request.GET.gname }}&cid={{ com.id }}" style="color: white; margin-right: 20px;" target="_blank">重新编辑 <span class="glyphicon glyphicon-edit"></span></a></div>
        {% endif %}
        </div>
        <div class="panel-body">
            <div id="question_com_{{ com.id }}">
                    <!-- Server-side output Markdown text -->
                <textarea style="display:none;">{{ com.content }}</textarea>             
            </div>
            {% if com.replys|length != 0 %}
            <div class="col-md-10">
                <table class="table">
            {% for reply in com.replys %}
                <tr>
                    <td>{{ reply.content }} - <a href="/user/?uid={{ reply.user.uid }}">{{ reply.user.name }}</a> <small>{{ reply.time }}</small>{% if reply.user.uid == user.uid %} <a href="/community/question_delete?q={{ request.GET.q }}&id={{ reply.id }}&t=qr&gname={{ request.GET.gname }}"><span class="glyphicon glyphicon-trash"></span></a> {% endif %}</td>
                </tr>
            {% endfor %}
                </table>
            </div>
            {% endif %}
            {% if user != None and question.status != 4 %}
            <div class="col-md-10">
                <form action="{{ request.get_full_path }}&p={{ com.id }}" method="POST">
                {% csrf_token %}
                    <div class="input-group">
                        <input type="text" class="form-control" placeholder="Quick Reply" name="rtext">
                        <span class="input-group-btn">
                            <button class="btn btn-default" type="submit">Reply</button>
                        </span>
                    </div><!-- /input-group -->
                </form>
            </div>
            {% endif %}
        </div>
        <div class="panel-footer text-right"><div class="navbar-left"><a href="#F{{ com.id }}">F{{ forloop.counter }}</a></div>{{ com.time }}</div>
    </div>
    <script type="text/javascript">
    $(function() {
        var testView = editormd.markdownToHTML("question_com_{{ com.id }}", {
            // markdown : "[TOC]\n### Hello world!\n## Heading 2", // Also, you can dynamic set Markdown text
            // htmlDecode : true,  // Enable / disable HTML tag encode.
            // htmlDecode : "style,script,iframe",  // Note: If enabled, you should filter some dangerous HTML tags for website security.
        });
    });
    </script>  
</div>
{% endfor %}
{% if user != None and question.status != 4 %}
<div class="col-md-10 col-md-offset-0">

        <form id="markdown-text" action="{{ request.get_full_path }}" method="POST" class="form-horizontal">
        {% csrf_token %}
          <div id="editor" style="z-index:1;">
              <textarea id="q-md" name="ctext" style="display:none;"></textarea>
          </div>
          <div class="col-md-2 navbar-right" style="margin-bottom: 200px;">
            <button class="btn btn-success navbar-right" type="submit" style="margin-right: 8px;">回复</button>
          </div>
          <script type="text/javascript">
            // function jssubmitText(n) = document.getElementById('markdown-text').action=""
          </script>
        </form>
      <script src="/static/editor.md/editormd.min.js"></script>
      <script type="text/javascript">
          $(function() {
              var editor = editormd("editor", {
                  // width: "100%",
                  height: "400px",
                  autoFocus: false,
                  placeholder: "使用Markdown编辑回复内容...",
                  // markdown: "xxxx",     // dynamic set Markdown text
                  path : "/static/editor.md/lib/"  // Autoload modules mode, codemirror, marked... dependents libs path
              });
          });
      </script>
</div>
{% endif %}
<script src="/static/editor.md/editormd.min.js"></script>
<script src="/static/editor.md/editormd.js"></script>
<script src="/static/editor.md/lib/marked.min.js"></script>
<script src="/static/editor.md/lib/prettify.min.js"></script>
</div>
{% endblock main_div %}